package com.jjt.kiki.ip.strategy;

import java.util.ArrayList;
import java.util.List;

import com.jjt.kiki.bean.Ip;
import com.jjt.kiki.ip.IpCrawlerException;

public class XiciDaili  implements IpCrawlerStrategy{

	String address = "http://api.xicidaili.com/free2016.txt";
	@Override
	public String getAddress() {
		return address;
	}

	@Override
	public boolean isBrowser() {
		return false;
	}

	@Override
	public List<Ip> analyse(String pageSource) throws IpCrawlerException {
		List<Ip> list = new ArrayList<Ip>();
		String[] ipArr = pageSource.split("\r\n");
		for(String ips:ipArr) {
			String[] ipA = ips.split(":");
			Ip ip = new Ip();
			ip.setIpHost(ipA[0]);
//			System.out.println(ipA[1]);
			ip.setIpPort(Integer.parseInt(ipA[1]));
			list.add(ip);
		}
		return list;
	}

}
